package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.ShopModel;

/**
 * Created by qi.wang on 2017/3/16.
 */

public class CarShopLikeAdapter extends BaseAdapter{
    public List<ShopModel.ListRecommendBean> list=new ArrayList<>();
    Context context;
    LayoutInflater inflater;

    public CarShopLikeAdapter(Context context, List<ShopModel.ListRecommendBean> data){
        this.context=context;
        this.list=data;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView=inflater.inflate(R.layout.list_item_car_shop_like,parent,false);
            holder.grid_name=(TextView)convertView.findViewById(R.id.grid_name);
            holder.grid_img=(ImageView) convertView.findViewById(R.id.grid_img);
            holder.newPrice=(TextView)convertView.findViewById(R.id.newPrice);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        ShopModel.ListRecommendBean newsModel=list.get(position);
        holder.grid_name.setText(newsModel.getGoods_name());
        holder.newPrice.setText("¥"+newsModel.getPrice());
        try {
            if(newsModel.getGoods_id().equals("1")) {
                Glide.with(context).load(newsModel.getImages()).asBitmap().error(R.mipmap.img3).into(holder.grid_img);
            }else if(newsModel.getGoods_id().equals("2")) {
                Glide.with(context).load(newsModel.getImages()).asBitmap().error(R.mipmap.img2).into(holder.grid_img);
            }else {
                Glide.with(context).load(newsModel.getImages()).asBitmap().error(R.mipmap.img1).into(holder.grid_img);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return convertView;
    }

    public static class ViewHolder{
        TextView grid_name,newPrice;
        ImageView grid_img;
    }
}
